/**
 *=============================================================================
 *  @copyright (C)      2025CCUT_1024lab_Damocles
 *
 *  @file    template.c
 *  @brief   封装模块代码规范
 *
 *  @note    使用方法
 *
 *  @attention 注意事项
 *-----------------------------------------------------------------------------
 *  @version    @author    @date    @note
 *  V1.0.0      Cherno    250808    done
 *
 *==============================================================================
 */

/*==============================Includes======================================*/
#include "CAN_receive.h"
#include "cmsis_os2.h"
#include "dvc_djimotor.h"
/*==============================PrivateMacros=================================*/

/*==============================PrivateTypes==================================*/

/*==============================PrivateVariables==============================*/
extern GM6020 GM6020_1;
/*==============================PrivateFunctionDeclarations===================*/
void CAN1_RxCpltCallBack(can_rx_buffer_t *can_message);
void CAN2_xCpltCallBack(can_rx_buffer_t *can_message);
/*==============================FunctionPrototypes============================*/

void can_receive_init()
{
	can_init(&hcan1, CAN1_RxCpltCallBack);
	// can_init(hcan2, CAN2_xCpltCallBack);

	GM6020_1.init(&hcan1, DJI_ID_0x206, OMEGA_CTRL, 0);

	// GM6020_1.pid_omega.init(70.0f, 0.0f, 0.0f, 0.0f, 10000.0f, 30000.0f);

	// GM6020_1.pid_omega.init(20.0f, 10.0f, 0.0f, 0.0f, 10000.0f, 30000.0f);
	// GM6020_1.pid_angle.init(2.0f, 0.0f, 2.0f, 10.0f, 8191, 8191);

	GM6020_1.pid_omega.init(20.0f, 5.0f, 0.0f, 0.0f, 10000.0f, 30000.0f);
	// GM6020_1.pid_angle.init(0.0f, 0.0f, 0.0f, 0.0f, 8191, 8191);
}

void can_receive_task(void *argument)
{
	can_receive_init();
	GM6020_1.set_target_omega(100);

	// GM6020_1.set_target_angle(320);

	while (1) {

		GM6020_1.pid_calc();

		can_send_data(&hcan1, 0x1ff, can1_0x1ff_tx_data, 8);
	
		osDelay(2);
	}
}

void CAN1_RxCpltCallBack(can_rx_buffer_t *can_message)
{
	switch (can_message->header.StdId) {
		case (0x1f): {
		} break;
		case (0x201): {
			GM6020_1.CAN_RxCpltCallback(can_message->data);
		} break;
		case (0x202): {
			GM6020_1.CAN_RxCpltCallback(can_message->data);
		} break;
		case (0x203): {
			GM6020_1.CAN_RxCpltCallback(can_message->data);
		} break;
		case (0x204): {
			GM6020_1.CAN_RxCpltCallback(can_message->data);
		} break;
		case (0x205): {
			GM6020_1.CAN_RxCpltCallback(can_message->data);
		} break;
		case (0x206): {
			GM6020_1.CAN_RxCpltCallback(can_message->data);
		} break;
		case (0x207): {
			GM6020_1.CAN_RxCpltCallback(can_message->data);
		} break;
		default: {
		} break;
	}
}

void CAN2_xCpltCallBack(can_rx_buffer_t *can_message)
{
	switch (can_message->header.StdId) {
		case (0x1f): {
		} break;
		case (0x201): {
		} break;
		case (0x202): {
		} break;
		case (0x203): {
		} break;
		case (0x204): {
		} break;
		case (0x205): {
		} break;
		case (0x206): {
		} break;
		case (0x207): {
		} break;
		default: {
		} break;
	}
}

/*========================COPYRIGHT(C) CCUT-DAMOCLES==========================*/
